﻿using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Model;

using Utility;

namespace DAL
{
    public class UserService
    {
        public int CreateUser(User user)
        {
            MySqlParameter[] parms = new MySqlParameter[] {
                new MySqlParameter("?UserID",user.UID),
                new MySqlParameter("?Fname",user.FirstName),
                new MySqlParameter("?Lname",user.LastName),
                new MySqlParameter("?EMail",user.Mail)
            };

            return MySQLHelper.ExecuteNonQuery("sp_CreateUser", parms);
        }

        public int VoteByID(string UID, int IID)
        {
            MySqlParameter parm = new MySqlParameter("?Ret", MySqlDbType.Int32);
            parm.Direction = System.Data.ParameterDirection.Output;
            parm.Value = 0;

            MySqlParameter[] parms = new MySqlParameter[] {
                parm,
                new MySqlParameter("?UserID",UID),
                new MySqlParameter("?IdeaID",IID)
            };

            MySQLHelper.ExecuteNonQuery("sp_VoteByID", parms);

            return Convert.ToInt32(parm.Value);
        }
    }
}
